import React from 'react'
import {View, Image, ScrollView } from 'react-native'
import { Carousel } from "../_teaset"
import { Dialog, Lt, Color, Label, Touch, Jpp, Jx, Cimage } from "../_utils"
import { Net, NET_GET, NET_NT, NET_ND, NET_NR } from "../_net"
import { cHome, eApp } from './_home';

// 首页轮播图
export class HomeBanner extends React.PureComponent{
    constructor(props){
        super(props);
        this.state = {
            banners:[{imgUrl:""}], //[""],
        }
    }
    componentWillMount(){
        Net.request("other/indexBanner", null, { NET_GET, NET_ND, NET_NR }).then(r=>{
            if(Jx.isArray(r.data) && r.data.length > 0){
                this.setState({banners:r.data});
            }
        });
        return;
        Net.request("other/banner", null, {NET_GET, NET_NT }).then(r=>{
            if(Jx.isArray(r.data) && r.data.length > 0){
                this.setState({banners:r.data});
            }
        });
    }
    onBanner(idx, banner){
        if(!banner.imgUrl){
            return;
        }
        cHome.jump2detail(cHome.toDataForHomeBanner(banner));
        return;
        console.warn(idx + ":" + banner);
    }
    render(){
        const { banners } = this.state;
        return <Carousel 
            control = {true} carousel = {true} cycle = {true}
            style = {{width:Jpp.width, height:Jpp.width/2}} 
        >
        {
            banners.map((v, i)=>{
                return <Touch key = {i} onPress = {this.onBanner.bind(this, i, v)}>
                    <Cimage 
                        style = {{width:Jpp.width, height:Jpp.width/2}}
                        uri = {v.Url}
                    />
                </Touch>
            })
        }
        </Carousel>;
    }
}